package com.example.myxutil;

import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.ResType;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ResInject;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

/**
 * 通过注解 + 反射机制初始化UI、事件监听、资源文件、IOC控制反转
 */

@ContentView(R.layout.activity_main)
public class MainActivity extends AppCompatActivity{
    @ViewInject(R.id.tv_activity)
    private TextView textView;
    @ViewInject(R.id.btn_activity)
    private Button btn;
    @ViewInject(R.id.iv_activity)
    private ImageView imageView;

    @ResInject(id = R.string.app_name,type = ResType.String)
    private String appName;
    @ResInject(id = R.mipmap.ic_launcher,type = ResType.Drawable)
    private Drawable drawable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.activity_main);
        ViewUtils.inject(this);
        initView();
    }

    private void initView() {
        textView.setText("youxiao");
        btn.setText("dianwo");
        imageView.setImageResource(R.mipmap.ic_launcher);

    }

    @OnClick({R.id.iv_activity,R.id.tv_activity,R.id.btn_activity})
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_activity:
                Toast.makeText(this,"test",Toast.LENGTH_LONG).show();
                break;
            case R.id.tv_activity:
                Toast.makeText(this,"button",Toast.LENGTH_LONG).show();
                break;
            case R.id.iv_activity:
                Toast.makeText(this,"image",Toast.LENGTH_LONG).show();
                break;
        }
    }
}
